home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: circle.c
-
- Purpose: This is a WDEF that implements a circular window.
-
-
- Circle WDEF -=- a circular window
- Copyright ©1994, Mark Pilgrim
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #define kTitleWidth 2 /* change to your liking */
-
- #define hstructure (*theWindow).strucRgn /* leave this alone */
- #define hcontent (*theWindow).contRgn /* leave this alone */
-
- // window definition ID = (WDEF resource ID)*16 + window variation code
- //
- // window variation code masks
- #define kShowTitle 0x0001 /* not supported */
- #define kNoGrowBox 0x0002 /* never show grow box if kTitleWidth<18 */
- #define kTitleBarIsBlack 0x0004 /* if off, title bar is grey */
-
- pascal long main(int varCode, WindowPeek theWindow, int message, long param);
-
- pascal long main(int varCode, WindowPeek theWindow, int message, long param)
- {
- typedef Rect *RPtr;
- Rect r, rclose, rgrow;
- int i, j;
- Point p;
- GrafPtr temp;
- PenState pnState;
- RgnHandle frame;
- Pattern pat;
-
- GetPort(&temp);
- SetPort((GrafPtr)theWindow);
- r=(*((GrafPtr)theWindow)).portRect;
- i=r.right-r.left;
- j=r.bottom-r.top;
- if (i>j) i=j;
- r.left=r.top=0;
- LocalToGlobal(&r);
- SetPort(temp);
- r.bottom=r.top+i;
- r.right=r.left+i;
-
- j=(i/2)+((i/2)*10)/14;
- rgrow.right=r.left+j;
- rgrow.bottom=r.top+j;
- rgrow.left=rgrow.right-12;
- rgrow.top=rgrow.bottom-12;
-
- SetRect(&rclose, r.left+3, r.top+(i/2)-6, r.left+14, r.top+(i/2)+5);
-
- switch (message)
- {
- case wDraw:
- if (!((*theWindow).visible)) break;
- if (param==0L)
- {
- pat[0]=pat[2]=pat[4]=pat[6]=
- (((*theWindow).hilited) && (varCode&kTitleBarIsBlack)) ? 0xFF :
- ((*theWindow).hilited) ? 0x55 : 0x00;
- pat[1]=pat[3]=pat[5]=pat[7]=
- (((*theWindow).hilited) && (varCode&kTitleBarIsBlack)) ? 0xFF :
- ((*theWindow).hilited) ? 0xAA : 0x00;
-
- FrameOval(&r);
- InsetRect(&r, 1, 1);
- frame=NewRgn();
- OpenRgn();
- FrameOval(&r);
- InsetRect(&r, kTitleWidth-2, kTitleWidth-2);
- FrameOval(&r);
- CloseRgn(frame);
- FillRgn(frame, &pat);
- DisposeRgn(frame);
- FrameOval(&r);
-
- if (((*theWindow).hilited) && ((*theWindow).goAwayFlag))
- {
- EraseRect(&rclose);
- FrameRect(&rclose);
- }
-
- if (((*theWindow).hilited) && ((varCode&kNoGrowBox)==0))
- {
- EraseRect(&rgrow);
- FrameRect(&rgrow);
- }
-
- // if (varCode&0x0001)
- // {
- // would draw title in here if we supported that
- // }
- }
- else if (param==4L)
- {
- GetPenState(&pnState);
- PenMode(patXor);
- MoveTo(rclose.left+2, rclose.top+2);
- Line(6, 6);
- MoveTo(rclose.left+2, rclose.bottom-3);
- Line(6,-6);
- MoveTo(rclose.left+1, rclose.top+5);
- Line(8, 0);
- MoveTo(rclose.left+5, rclose.top+1);
- Line(0, 8);
- InsetRect(&rclose, 4, 4);
- EraseRect(&rclose);
- SetPenState(&pnState);
- }
- break;
- case wHit:
- p.v=HiWord(param);
- p.h=LoWord(param);
- if (PtInRgn(p, hcontent)) return 1L;
- else if (((*theWindow).hilited) && ((*theWindow).goAwayFlag) &&
- (PtInRect(p, &rclose))) return 4L;
- else if (((*theWindow).hilited) && ((varCode&kNoGrowBox)==0) &&
- (PtInRect(p, &rgrow))) return 3L;
- else if (PtInRgn(p, hstructure)) return 2L;
- break;
- case wCalcRgns:
- SetEmptyRgn(hstructure);
- OpenRgn();
- FrameOval(&r);
- CloseRgn(hstructure);
- // if (varCode&kShowTitle)
- // {
- // would define title region in here if we supported that
- // }
- InsetRect(&r, kTitleWidth, kTitleWidth);
- SetEmptyRgn(hcontent);
- OpenRgn();
- FrameOval(&r);
- CloseRgn(hcontent);
- break;
- case wNew:
- break;
- case wDispose:
- break;
- case wGrow:
- r=*(RPtr)param;
- i=r.right-r.left;
- j=r.bottom-r.top;
- if (i>j) i=j;
- r.right=r.left+i;
- r.bottom=r.top+i;
- FrameOval(&r);
- break;
- case wDrawGIcon:
- break;
- }
-
- return 0L;
- }
-